var limsReport = Gikam.getPageObject({

    getEditListColumns : function() {
        return [ {
            checkbox : true
        }, {index: true},Gikam.status.getBpmnColumn(limsReport.workflow.dbTable), {
            field : 'reportNo',
            title : 'T_LIMS_REPORT.REPORTNO'
        }, {
            field : 'batchCode',
            title : 'T_LIMS_REPORT.BATCHCODE'
        }, /*{
            field : 'productCode',
            title : 'T_LIMS_REPORT.PRODUCTCODE'
        }, */{
            field : 'productName',
            title : 'T_LIMS_REPORT.PRODUCTNAME'
        }, {
            field : 'sampleCodes',
            title : 'T_LIMS_REPORT.SAMPLECODES'
        }, /*{
            field : 'folderCodes',
            title : 'T_LIMS_REPORT.FOLDERCODES',
            type : 'choose',
            category: 'pre-folder-choose',
            editor : true,
            // single: true,
            onBeforeChoose : function(){
                return {
                    fstatus_EQ : 'done',
                    batchId_EQ : this.getActivedRow().batchId,
                    productId_EQ : this.getActivedRow().productId,
                    sampleId_IN : this.getActivedRow().sampleIds
                }
            },
            onAfterChoose: function (rows, index) {
                let samples = this.getActivedRow().sampleCodes.split(",");
                if (rows) {
                    debugger
                    if(rows.length !== samples.length) {
                        Gikam.alert("T_LIMS_REPORT.CHOOSE_FOLDER.CHECK")
                        return
                    }
                    for (let i = 0; i < samples.length; i++) {
                        let filter = rows.filter(r => samples[i] === r.sampleCode);
                        if(Gikam.isEmpty(filter)) {
                            Gikam.alert("T_LIMS_REPORT.CHOOSE_FOLDER.CHECK")
                            return
                        }
                    }

                    this.setData({
                        index: index,
                        folderIds: rows.map(e => e.ext$.folderid).join(","),
                        folderCodes: rows.map(e => e.experimentNo).join(",")
                    })
                }
            },
            onClean: function (field, value, index) {
                this.setData({
                    index: index,
                    reportTemplateId: '',
                    reportTemplateCode: '',
                    reportTemplateName: ''
                })
            },
        },*/ {
            field : 'reportTemplateName',
            title : 'T_LIMS_REPORT.REPORTTEMPLATENAME',
            type : 'choose',
            category: 'report-template-choose',
            editor : true,
            single: true,
            onBeforeChoose : function(){
                return {
                    templateType_EQ : 'report'
                }
            },
            onAfterChoose: function (rows, index) {
                if (rows) {
                    this.setData({
                        index: index,
                        reportTemplateId: rows[0].id,
                        reportTemplateCode: rows[0].templateCode,
                        reportTemplateName: rows[0].templateName
                    })
                }
            },
            onClean: function (field, value, index) {
                this.setData({
                    index: index,
                    reportTemplateId: '',
                    reportTemplateCode: '',
                    reportTemplateName: ''
                })
            },
        }, {
        //     field : 'generatorId',
        //     title : 'T_LIMS_REPORT.GENERATORID'
        // }, {
        //     field : 'generator',
        //     title : 'T_LIMS_REPORT.GENERATOR'
        // }, {
        //     field : 'signerId',
        //     title : 'T_LIMS_REPORT.SIGNERID'
        // }, {
        //     field : 'signer',
        //     title : 'T_LIMS_REPORT.SIGNER'
        // }, {
            field : 'remark',
            title : 'T_LIMS_REPORT.REMARK',
            editor : true
        }, /*{
            field : 'reportFileName',
            title : 'T_LIMS_REPORT.REPORTFILENAME'
        },*/ {
            field: 'createdByName',
            title: 'T_LIMS_REPORT.CREATEDBYNAME',
        }, {
            field: 'createdTime',
            title: 'T_LIMS_REPORT.CREATEDTIME',
            width : 150,
            type: 'dateTime',
        }, {
            field: 'createdByOrgName',
            title: 'T_LIMS_REPORT.CREATEDBYORGNAME',
        } ];
    },

    getBaseInfoFormFields : function() {
        return [ {
            field : 'reportNo',
            title : 'T_LIMS_REPORT.REPORTNO',
            validators : [ 'strLength[0,11]' ]
        }, {
            field : 'batchCode',
            title : 'T_LIMS_REPORT.BATCHCODE',
            validators : [ 'strLength[0,11]' ]
        }, /*{
            field : 'productCode',
            title : 'T_LIMS_REPORT.PRODUCTCODE',
            validators : [ 'strLength[0,11]' ]
        }, */{
            field : 'productName',
            title : 'T_LIMS_REPORT.PRODUCTNAME',
            validators : [ 'strLength[0,22]' ]
        }, {
            field : 'sampleIds',
            title : 'T_LIMS_REPORT.SAMPLEIDS',
            validators : [ 'strLength[0,33]' ]
        }, {
            field : 'sampleCodes',
            title : 'T_LIMS_REPORT.SAMPLECODES',
            validators : [ 'strLength[0,33]' ]
        }, {
            field : 'folderIds',
            title : 'T_LIMS_REPORT.FOLDERIDS',
            validators : [ 'strLength[0,33]' ]
        }, {
            field : 'folderCodes',
            title : 'T_LIMS_REPORT.FOLDERCODES',
            validators : [ 'strLength[0,33]' ]
        }, {
            field : 'generatorId',
            title : 'T_LIMS_REPORT.GENERATORID',
            validators : [ 'strLength[0,11]' ]
        }, {
            field : 'generator',
            title : 'T_LIMS_REPORT.GENERATOR',
            validators : [ 'strLength[0,11]' ]
        }, {
            field : 'signerId',
            title : 'T_LIMS_REPORT.SIGNERID',
            validators : [ 'strLength[0,11]' ]
        }, {
            field : 'signer',
            title : 'T_LIMS_REPORT.SIGNER',
            validators : [ 'strLength[0,11]' ]
        }, {
            field : 'remark',
            title : 'T_LIMS_REPORT.REMARK',
            validators : [ 'strLength[0,22]' ]
        }, {
            field : 'reportFileName',
            title : 'T_LIMS_REPORT.REPORTFILENAME',
            validators : [ 'strLength[0,22]' ]
        }, ];
    },

    getAuditListColumns : function() {
        return [ {
            checkbox : true
        }, {index: true},Gikam.status.getBpmnColumn(limsReport.workflow.dbTable), {
            field : 'reportNo',
            title : 'T_LIMS_REPORT.REPORTNO'
        }, {
            field : 'batchCode',
            title : 'T_LIMS_REPORT.BATCHCODE'
        }, /*{
            field : 'productCode',
            title : 'T_LIMS_REPORT.PRODUCTCODE'
        }, */{
            field : 'productName',
            title : 'T_LIMS_REPORT.PRODUCTNAME'
        }, {
            field : 'sampleCodes',
            title : 'T_LIMS_REPORT.SAMPLECODES'
        }, /*{
            field : 'folderCodes',
            title : 'T_LIMS_REPORT.FOLDERCODES'
        },*/ {
            field : 'generator',
            title : 'T_LIMS_REPORT.GENERATOR'
        }, {
            field : 'remark',
            title : 'T_LIMS_REPORT.REMARK'
        }, /*{
            field : 'reportFileName',
            title : 'T_LIMS_REPORT.REPORTFILENAME'
        }*/ ];
    },

    getSearchListColumns : function() {
        return [ {
            checkbox : true
        }, {index: true},Gikam.status.getBpmnColumn(limsReport.workflow.dbTable), {
            field : 'reportNo',
            title : 'T_LIMS_REPORT.REPORTNO'
        }, {
            field : 'batchCode',
            title : 'T_LIMS_REPORT.BATCHCODE'
        }, /*{
            field : 'productCode',
            title : 'T_LIMS_REPORT.PRODUCTCODE'
        }, */{
            field : 'productName',
            title : 'T_LIMS_REPORT.PRODUCTNAME'
        },  {
            field : 'sampleCodes',
            title : 'T_LIMS_REPORT.SAMPLECODES'
        }, /*{
            field : 'folderCodes',
            title : 'T_LIMS_REPORT.FOLDERCODES'
        }, */{
            field : 'generator',
            title : 'T_LIMS_REPORT.GENERATOR'
        }, {
            field : 'signer',
            title : 'T_LIMS_REPORT.SIGNER'
        }, {
            field : 'remark',
            title : 'T_LIMS_REPORT.REMARK'
        }, /*{
            field : 'reportFileName',
            title : 'T_LIMS_REPORT.REPORTFILENAME'
        } */];
    },

    baseUrl : IFM_CONTEXT + '/secure/basemodule/business/reports',

    workflow : {
        dbTable : 'T_LIMS_REPORT',
        columns : [ {
            field : 'id',
            title : 'T_LIMS_REPORT.ID'
        } ]
    },

    downloadReport: function (gridComponent) {
        var grid = Gikam.getComp(gridComponent);
        var selections = grid.getSelections();
        if (Gikam.isEmpty(selections)) {
            Gikam.alert('GIKAM.TIP.CHOOSE_AT_LEAST_ONE_ITEM');
            return;
        }
        var bool = selections.filter(f => Gikam.isNotEmpty(f.reportFileName));
        if (bool.length === 0) {
            Gikam.alert('not found any report, you can not download it now!');
            return;
        }
        Gikam.getText(limsreport.baseUrl + '/download/reports' + Gikam.param({
            ids: selections.map(function (item) {
                return item.id;
            }).join(',')
        })).done(function (url) {
            if (url != '-1') {
                Gikam.download(url);
            }else{
                Gikam.alert('GIKAM.ALERT.MESSAGE.REPORT.DOWNLOAD.FIALED');
            }
        }).always(function () {
            workspace.window.closeMask();
        });
    },
});
